home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / utilitys / 388 / newspeed / newspeed.s < prev    next >
Text File  |  1990-03-08  |  13KB  |  353 lines

  1. ;*************************************************
  2. ;* NEWSPEED  by  William A. Schneider            *
  3. ;* Copyright 1989 Antic Publishing               *
  4. ;*                                               *
  5. ;*                                               *
  6. ;* This program is a terminate-&-stay-resident   *
  7. ;* utility -- place it in the AUTO folder and    *
  8. ;* it will be installed at boot-up or run it     *
  9. ;* from the desktop.  It will not survive a      *
  10. ;* warm boot.                                    *
  11. ;*************************************************
  12.  
  13. resetsp equ      $0    ;4 byte value for Stack Pointer after reset
  14. resetpc equ      $4    ;4 byte value for Program Counter after reset
  15. timerc equ     $114    ;timer C (system clock) interrupt vector
  16.                        ;   executed 200 times per second
  17. memvalid equ   $420    ;4 byte value for valid memory configuration
  18. flock equ      $43e    ;2 byte value = 0 if no disk access in progress
  19. sysbase equ    $4f2    ;4 byte pointer to start of operating system
  20. hz_200 equ     $4ba    ;4 byte value that is incremented by 1 with
  21.                        ;   each clock cycle (200 times per sec)
  22.  
  23. begin:
  24.  
  25. message:
  26. ; Send installation message to screen
  27.  move.l  #installmessage,-(sp)     ;point to installation message
  28.  move.w  #$09,-(sp)                ;GEMDOS PRINT LINE command
  29.  trap    #1                        ;print the message on the screen
  30.  addq.l  #6,sp                     ;restore stack
  31.  
  32.  bsr     sound
  33.  
  34. ; Send blank lines to screen
  35.  move.l  #blanklines,-(sp)     
  36.  move.w  #$09,-(sp)            
  37.  trap    #1                    
  38.  addq.l  #6,sp                 
  39.  
  40. ; Call code that installs hooks in SUPVR mode
  41.  move.l  #hook,-(sp)               ;point to code at hooks
  42.  move.w  #38,-(sp)                 ;XBIOS SUPER mode command
  43.  trap    #14                       ;execute code at hooks in supvr mode
  44.  addq.l  #6,sp                     ;restore stack
  45.  
  46. ; Terminate program and protect memory for TSR code
  47.  clr.w   -(sp)                     ;termination code of 0
  48.  move.l  #(finish-begin+256),-(sp) ;bytes to protect at program start
  49.  move.w  #$31,-(sp)                ;GEMDOS KEEP PROCESS command
  50.  trap    #1                        ;terminate and protect memory
  51.  
  52. ; Subroutine to install hook
  53. hook:
  54. ; Install hook to delay routine
  55.  move.l  timerc,oldtimer   ;save timer C vector
  56.  move.l  #tsrcode,timerc   ;redirect timer C to delay routine
  57.                                             
  58. ; Determine memory location for keyboard shift status.
  59.  move.l  #$e1b,d0          ;location for pre-1987 ROMs
  60.  movea.l $4f2,a0           ;pointer to start of operating system
  61.  cmpi.w  #$1988,$1a(a0)    ;check for ROM creation year
  62.  bne.s   tstfor1987
  63.  move.l  #$e63,D0          ;location for 1988 ROMs
  64.  bra.s   dateset
  65. tstfor1987:
  66.  cmpi.w  #$1987,$1a(a0)
  67.  bne.s   dateset
  68.  move.l  #$e61,d0          ;location for 1987 ROMs
  69. dateset:
  70.  move.l  d0,key            ;save location of keyboard shift status
  71.  
  72. ; Pause 2 sec to read installation message
  73. ; (Is in hook routine because next instruction must execute in supvr mode)
  74.  move.l  hz_200,d0         ;get current clock count
  75.  add.l   pausesec,d0       ;change to what clock count will be after pause
  76. messagepause:
  77.  cmp.l   hz_200,d0              ;pause for 2 sec after key was selected
  78.  bne     messagepause
  79.  
  80.  rts
  81.  
  82. ;-----------------------------------------------------------------------
  83. ; TSR code that executes 200 times per second
  84.  
  85. tsrcode:
  86.  
  87.  tst.w   flock             ;test for disk access
  88.  bne     return            ;return if access in progress (<>0)
  89.  
  90.  move.w  sr,-(sp)          ;save status register to restore
  91.                        ;   when we exit
  92.  
  93. ;set the interrupt to 5 so the MFP interrupts (which includes timer C)
  94. ;will be disabled.  If left active, our routine would be interrupted
  95. ;200 times per second by itself and lock up.
  96.  
  97.  move.w  #$2500,sr         ;supvr mode, set interrupt at 5
  98.  
  99.  movem.l d0/a0,-(sp)       ;save to restore when we exit
  100.  movea.l key,a0            ;load location of keyboard shift status byte
  101.  move.b  (a0),d0           ;move keyboard shift status byte to d0
  102.  andi.b  #$f,d0           ;strip bits 4 thru 7 to strip caps lock bit
  103.  cmp.b   hotkey,d0         ;check for Ctl+Alt
  104.  bne     delaycode         ;branch if not Ctl+Alt
  105.  
  106.  movem.l d6/a1/a6,-(sp)    ;save registers to restore when we exit
  107.  
  108. ;Stop all sound by writing $FF into sound register 7, the 
  109. ;noise/tone/port enable register.  To place a value into a sound
  110. ;register, you must:
  111. ;   - put the selected register number (0-15) into $FF8800
  112. ;   - write the byte to be placed in the selected register into $FF8802
  113. ;The XBIOS 28 Giaccess routine could also be used.
  114.  move.l  #$ff8800,a0
  115.  move.b  #7,(a0)    
  116.  move.l  #$ff8802,a1    
  117.  move.b  #$ff,(a1)
  118.  
  119. ; Get screen address
  120.  move.w  #2,-(sp)          ;XBIOS PHYSBASE command
  121.  trap    #14               ;get screen base address
  122.  addq.l  #2,sp             ;restore stack
  123.  move.l  d0,scrnadrs       ;save scrnadrs
  124.  
  125. ; Save top line of screen for later restore
  126.  movea.l  d0,a0            ;screen start address
  127.  movea.l  #scrnstorage,a1  ;temp buffer to hold top line
  128.  move.l   #1440,d0         ;number of bytes to save
  129. scrnsave:
  130.  move.b  (a0)+,(a1)+       ;copy 1st 1440 bytes of screen
  131.  dbra    d0,scrnsave       ;   to scrnstorage
  132.  
  133. ; I cannot be sure what color combinations may be in place during
  134. ; the program in progress.  Therefore, to be sure that our prompt
  135. ; will be visible, we will need to set our own colors.  First we
  136. ; will save the current colors for later restoration.
  137.  
  138. ; Save the original palette
  139.  move.l  #15,d6            ;set up counter and color number
  140.  movea.l #origpalette,a6   ;area to save colors
  141. savecolors:
  142.  move.w  #-1,-(sp)         ;-1 returns current color value
  143.  move.w  d6,-(sp)          ;color number
  144.  move.w  #7,-(sp)          ;XBIOS SET COLOR command
  145.  trap    #14               ;get color value
  146.  addq.l  #6,sp             ;restore stack
  147.  move.w  d0,(a6)+          ;save color value
  148.  dbra    d6,savecolors     ;do for 16 colors
  149.  
  150. ; In order to make our colors effective in all resolutions, I will
  151. ; set colors 1 thru 15 to black and color 0 to white.  This will
  152. ; also make it very evident when the screen changes that our hook
  153. ; is waiting for keyboard input.
  154.  
  155. ; Set colors 0 thru 15 to black
  156.  move.l  #15,d6            ;set up counter and color number
  157. setcolors:
  158.  move.w  #$777,-(sp)       ;value for black
  159.  move.w  d6,-(sp)          ;color number
  160.  move.w  #7,-(sp)          ;XBIOS SET COLOR command
  161.  trap    #14               ;change color value
  162.  addq.l  #6,sp             ;restore stack
  163.  dbra    d6,setcolors      ;do for 16 colors
  164.  
  165. ; Set color 0 to white
  166.  move.w  #0,-(sp)          ;value for white
  167.  move.w  #0,-(sp)          ;color number
  168.  move.w  #7,-(sp)          ;XBIOS SET COLOR command
  169.  trap    #14               ;change color value
  170.  addq.l  #6,sp             ;restore stack
  171.  
  172. ; Send choose message to screen
  173.  move.l  #choosemessage,-(sp)      ;point to choose message
  174.  move.w  #$09,-(sp)                ;GEMDOS PRINT LINE command
  175.  trap    #1                        ;print the message on the screen
  176.  addq.l  #6,sp                     ;restore stack
  177.  
  178. select_key:
  179. ; Get next key selected from keyboard
  180.  move.w  #2,-(sp)          ;read from console
  181.  move.w  #2,-(sp)          ;BIOS BCONIN command
  182.  trap    #13               ;get key code
  183.  addq.l  #4,sp             ;restore stack
  184.  
  185. ; After BCONIN, the ASCII code of the character selected is in the 
  186. ; lower byte of d0
  187.  
  188. chkforwarmboot:
  189.  cmpi.b  #$08,d0           ;check for backspace key
  190.  bne     chkforcoldboot    ;if no, check for cold boot
  191. ; Do a warmboot
  192.  move.w  resetsp,sp        ;set supvr stack pointer
  193.  move.l  resetpc,a0        ;load program counter
  194.  jmp     (a0)              ;jump to reset program counter
  195.  
  196. chkforcoldboot:
  197.  cmp.b   #$7f,d0           ;check for delete key
  198.  bne     chkforspeedchg    ;if no, check for speed change
  199.  
  200. ; Do a cold boot
  201. coldboot:
  202.  clr.l   memvalid          ;force a coldstart
  203.  move.l  sysbase,a0        ;find system base address
  204.  jmp     (a0)              ;jump to start of operating system
  205.  
  206. chkforspeedchg:
  207. ; Look for keys 0-9
  208.  
  209.  subi.b  #$30,d0           ;convert ASCII code to number 0-9
  210.  cmpi.b  #0,d0
  211.  blt     select_key        ;code out of range (below 0), try again
  212.  cmpi.b  #$9,d0
  213.  bgt     select_key        ;code out of range (above 9), try again
  214.  and.l   #255,d0           ;clear all but low byte
  215.  
  216. ; Calculate the delay loop counter value.
  217.  mulu    factor,d0         ;calc delay
  218.  move.l  d0,delay          ;save delay
  219.  
  220. ; Send pause message to screen
  221.  move.l  #pausemessage,-(sp)    ;point to pause message
  222.  move.w  #$09,-(sp)             ;GEMDOS PRINT LINE command
  223.  trap    #1                     ;print the message on the screen
  224.  addq.l  #6,sp                  ;restore stack
  225.  
  226. ;pause loop
  227.  move.l  #15,d0                
  228. pause1:
  229.  move.l  #$ffffff,d6
  230. pause2:
  231.  dbra    d6,pause2
  232.  dbra    d0,pause1
  233.  
  234. ; Restore original palette
  235.  move.l  #15,d6            ;set up counter and color number
  236.  movea.l #origpalette,a6   ;area where original colors are saved
  237. restorecolors:
  238.  move.w  (a6)+,-(sp)       ;color value
  239.  move.w  d6,-(sp)          ;color number
  240.  move.w  #7,-(sp)          ;XBIOS SET COLOR command
  241.  trap    #14               ;set color value
  242.  addq.l  #6,sp             ;restore stack
  243.  dbra    d6,restorecolors  ;do for 16 colors
  244.  
  245. ; Restore top screen line where message was written
  246.  movea.l scrnadrs,a0
  247.  movea.l #scrnstorage,a1
  248.  move.l  #1440,d0
  249. scrnrestore:
  250.  move.b  (a1)+,(a0)+
  251.  dbra    d0,scrnrestore
  252.  
  253.  movem.l (sp)+,d6/a1/a6
  254.  
  255. ;-----------------------------------------------------------------------
  256. ; Actual TSR slowdowm code
  257.  
  258. delaycode:
  259.  
  260.  cmpi.l  #0,delay
  261.  beq     enddelay          ;no slowdown if delay = 0
  262.  move.l  delay,d0          ;load delay counter
  263.  
  264. loop:                      ;actual delay loop
  265.  dbra    d0,loop
  266.  
  267. enddelay:
  268.  movem.l  (sp)+,d0/a0      ;restore registers
  269.  move.w  (sp)+,sr          ;restore status register
  270.  
  271. return:
  272.  move.l oldtimer,-(sp)
  273.  rts                       ;jump to old timer c vector
  274.  
  275. ; Sound subroutine
  276. sound:
  277.  move.l  #bell,-(sp)            
  278.  move.w  #$09,-(sp)        ;GEMDOS PRINT LINE command
  279.  trap    #1                ;sound bell
  280.  addq.l  #6,sp             ;restore stack
  281.  rts
  282.  
  283.  
  284. ; Working data area
  285.  
  286.  dc.b   " Next byte is hotkey"    ;marker to find patch byte position
  287. hotkey:                    ;special key combination to initiate
  288.  dc.b    $c               ;keyboard shift status for CTL + ALT
  289.                            ;If another combination is desired, 
  290.                            ;replace with one of the following
  291.                            ;   dc.b  $6      for CTL + LSHIFT
  292.                            ;   dc.b  $e      for CTL + LSHIFT + ALT
  293.                            ;   dc.b  $a      for LSHIFT + ALT
  294.  dc.b   0,0,0
  295. key:
  296.  dc.l   0                  ;keyboard code
  297.  
  298.  dc.b   "Next 4 bytes are message pause count"   ;marker to find patch byte
  299. pausesec:
  300.  dc.l   400                ;message pause count  400 = 2 seconds
  301. oldtimer:
  302.  dc.l   0                  ;original timer c vector
  303. factor:
  304.  dc.w   $0140              ;speed factor
  305. delay:
  306.  dc.l   0                  ;delay count
  307. scrndump:               
  308.  dc.l   0                  ;original screen dump vector
  309. scrnadrs:
  310.  dc.l   0                  ;screen start address
  311. scrnstorage:
  312.  ds.b    1440              ;storage space for 1 line of screen
  313. origpalette:
  314.  ds.w    16
  315.  
  316. ; Installation announcement string
  317. installmessage:
  318.  dc.b    27,"E"
  319.  dc.b    '**************************************',13,10
  320.  dc.b    '*  NEWSPEED by William A. Schneider  *',13,10
  321.  dc.b    '*  Copyright 1989 Antic Publishing   *',13,10
  322.  dc.b    '*                                    *',13,10
  323.  dc.b    '*      HOT KEY = CTL + ALT           *',13,10
  324.  dc.b    '*                                    *',13,10
  325.  dc.b    '*    After initiation:               *',13,10
  326.  dc.b    '*                                    *',13,10
  327.  dc.b    '*      Bksp for warm boot            *',13,10
  328.  dc.b    '*      Del for cold boot             *',13,10
  329.  dc.b    '*      # for new speed               *',13,10
  330.  dc.b    '*      Where #=0 for normal speed    *',13,10
  331.  dc.b    '*          1 is slower               *',13,10
  332.  dc.b    '*            - etc -                 *',13,10
  333.  dc.b    '*          9 is slowest              *',13,10
  334.  dc.b    '**************************************',13,10,10
  335.  
  336. blanklines:
  337.  dc.b    13,10,10,0
  338.  
  339. bell:
  340.  dc.b    7,0               ;bell code (7)
  341.  
  342. choosemessage:
  343.  dc.b    27,'H',27,'K'     ;VT52 codes to home
  344.                            ;  cursor then erase line
  345.  dc.b    'Select: Del (CBoot), Bksp (WBoot), 0-9',0    ;text to display
  346.  
  347. pausemessage:
  348.  dc.b    27,'H',27,'K'
  349.  dc.b    'Pausing - get ready to continue',0
  350.  
  351. finish:
  352.  end
  353.